﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TemplateMethod
{
    public abstract class SoyaMilk
    {
        /// <summary>
        /// 模板方法，定义步骤，算法
        /// </summary>
        public void Make() 
        {
            Select();
            if (CustomerWantCondiment())
            {
                AddCondiments();
            }       
            Soak();
            Beat();
        }

        public void Select()
        {
            Console.WriteLine("select good bean");
        }

        /// <summary>
        /// 每一个子类必须做的而且不一样的，定义成抽象方法
        /// </summary>
        public abstract void AddCondiments();

        /// <summary>
        /// 子类可能需要定制的，做成虚方法
        /// </summary>
        public virtual void Soak()
        {
            Console.WriteLine("soak 1 hour");
        }

        /// <summary>
        /// 钩子方法
        /// </summary>
        /// <returns></returns>
        public virtual bool CustomerWantCondiment()
        {
            return true;
        }

        public void Beat()
        {
            Console.WriteLine("beat 2 hour");
        }
    }
}
